<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组解构</title>
</head>

<body>
  <script>
    const arr = [100, 60, 80]
    const [max, min, avg] = arr
    console.log(max);
    console.log(min);
    console.log(avg);

    // 交换两个变量的值
    let a = 1
    let b = 2;
    [b, a] = [a, b]
    console.log(a, b);

    // 变量多,值少的情况
    const [q, w, e, r] = [2, 3, 4]
    console.log(r);  //undefined

    // 默认值
    const [t = 0, y = 0] = []
    console.log(t, y);

    // 多维数组解构
    const [g, h, [j, k]] = [1, 2, [3, 4]]
    console.log(g);
    console.log(h);
    console.log(j);
    console.log(k);
  </script>
</body>

</html>